Skip to main content

๐Ÿงช Kubernetes Hands-On Guide (Beginner Friendly)


Part 1 โ€” Setup


Step 1 โ€” Start Docker Desktopโ€‹

๐ŸŽฏ Why

Kubernetes in our lab runs inside Docker Desktop. If Docker is not running, Kubernetes will not work.

๐Ÿ›  Do

Open Docker Desktop and ensure it is running.

โœ… Expected

Dashboard loads normally.

๐Ÿง  Understand

Docker Desktop provides:

  • Container runtime
  • Kubernetes cluster (single node)

Step 2 โ€” Enable Kubernetesโ€‹

๐ŸŽฏ Why

Kubernetes must be enabled before we use kubectl.

๐Ÿ›  Do

  1. Docker Desktop โ†’ Settings
  2. Kubernetes
  3. Enable Kubernetes
  4. Apply & Restart
  5. Wait until status shows Running

โœ… Expected

Green status / Running.

๐Ÿง  Understand

You now have a single-node Kubernetes cluster on your laptop.


Step 3 โ€” Verify Kubernetes CLIโ€‹

๐ŸŽฏ Why

We use kubectl to talk to Kubernetes.

๐Ÿ›  Do

kubectl version --client

โœ… Expected

Client version shown.


Step 4 โ€” Check cluster connectionโ€‹

๐ŸŽฏ Why

Make sure kubectl is connected to correct cluster.

๐Ÿ›  Do

kubectl config current-context

โœ… Expected

Shows docker-desktop


Step 5 โ€” Check Nodeโ€‹

๐ŸŽฏ Why

Node = machine where pods run.

๐Ÿ›  Do

kubectl get nodes

โœ… Expected

1 node with status Ready.

๐Ÿง  Understand

Your laptop is acting as the Kubernetes node.


Part 2 โ€” Pods


Step 6 โ€” Create a Podโ€‹

๐ŸŽฏ Why

Pod is the smallest unit Kubernetes runs. Usually 1 pod = 1 container.

๐Ÿ›  Do

kubectl run nginx-pod --image=nginx

Step 7 โ€” Check Pod Statusโ€‹

๐Ÿ›  Do

kubectl get pods

โœ… Expected

nginx-pod โ†’ Running

๐Ÿง  Understand

Kubernetes:

  • Pulled nginx image
  • Created container
  • Assigned IP
  • Started it

Step 8 โ€” Inspect Podโ€‹

๐ŸŽฏ Why

See detailed information.

๐Ÿ›  Do

kubectl describe pod nginx-pod

Look at:

  • Image
  • Status
  • Events

Step 9 โ€” View Logsโ€‹

๐ŸŽฏ Why

Logs help debug.

๐Ÿ›  Do

kubectl logs nginx-pod

Step 10 โ€” Delete Podโ€‹

๐ŸŽฏ Why

Plain pod is NOT self-healing.

๐Ÿ›  Do

kubectl delete pod nginx-pod

Check:

kubectl get pods

โœ… Pod is gone permanently.

๐Ÿง  Understand

Pods alone are not managed.


Part 3 โ€” Deployment (Real Usage)


Step 11 โ€” Create Deploymentโ€‹

๐ŸŽฏ Why

Deployment manages pods:

  • Self-healing
  • Scaling
  • Rolling updates

๐Ÿ›  Do

kubectl create deployment demo --image=nginx

Step 12 โ€” Verify Deploymentโ€‹

kubectl get deployments
kubectl get pods

โœ… 1 deployment โœ… 1 pod (random name)


Step 13 โ€” Self Healing Testโ€‹

๐ŸŽฏ Why

Deployment keeps desired state.

๐Ÿ›  Do

Delete the pod:

kubectl delete pod <pod-name>

Check:

kubectl get pods

โœ… New pod appears automatically.

๐Ÿง  Understand

Deployment enforces:

"I want 1 pod always running."


Step 14 โ€” Scaleโ€‹

๐ŸŽฏ Why

Run multiple copies for load.

๐Ÿ›  Do

kubectl scale deployment demo --replicas=3

Check:

kubectl get pods

โœ… 3 pods running.

๐Ÿง  Understand

Kubernetes handles scaling automatically.


Part 4 โ€” Service (Networking)


Step 15 โ€” Expose Deploymentโ€‹

๐ŸŽฏ Why

Pods change names/IPs. Service provides stable access.

๐Ÿ›  Do

kubectl expose deployment demo --type=NodePort --port=80

Step 16 โ€” Check Serviceโ€‹

kubectl get services

Look at:

80:3xxxx/TCP

Open in browser:

http://localhost:<NodePort>

โœ… Nginx page loads.

๐Ÿง  Understand

Service:

  • Stable IP
  • Load balances to 3 pods

Part 5 โ€” Labels


Step 17 โ€” View Labelsโ€‹

๐ŸŽฏ Why

Labels connect objects.

๐Ÿ›  Do

kubectl get pods --show-labels

Youโ€™ll see something like:

app=demo

Step 18 โ€” Add Label to Deploymentโ€‹

kubectl label deployment demo team=devops

Check:

kubectl get deployment demo --show-labels

๐Ÿง  Understand

This labels the deployment object only.


Step 19 โ€” Add Label to Pod Template (Permanent)โ€‹

kubectl edit deployment demo

Find:

spec:
template:
metadata:
labels:

Add:

env: training

Save.

Check:

kubectl get pods --show-labels

โœ… Pods now have env=training

๐Ÿง  Understand

Service selectors match pod labels only.


Step 20 โ€” Filter Using Labelsโ€‹

kubectl get pods -l env=training

Only matching pods show.


Step 21 โ€” Remove Label from Podโ€‹

kubectl label pod <pod-name> env-

๐Ÿง  Temporary if deployment recreates pod.


Part 6 โ€” Cleanup


Step 22 โ€” Delete Everythingโ€‹

kubectl delete service demo
kubectl delete deployment demo

Verify:

kubectl get all

Cluster clean.


Final Concepts Students Should Know

ObjectPurpose
NodeMachine
PodRuns container
DeploymentManages pods
ReplicaNumber of pod copies
ServiceNetworking & load balance
LabelIdentifies objects
SelectorMatches labels